home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / FGFADE11.ZIP / FADE.BAS < prev    next >
BASIC Source File  |  1995-02-13  |  8KB  |  216 lines

  1. '*****************************************************************************
  2. '                                                                            *
  3. '  FADE.BAS                                                                  *
  4. '                                                                            *
  5. '  This program demonstrates how to perform a smooth palette fade with       *
  6. '  Fastgraph.  This example assumes a 256-color video mode with 6-bit DAC    *
  7. '  values (i.e., between 0 and 63).  These values are defined at the top of  *
  8. '  this file, so you can change them easily.                                 *
  9. '                                                                            *
  10. '  The fadein() and fadeout() routines in this program were originally       *
  11. '  written by John Wagner, author of the IMPROCES image processing program.  *
  12. '                                                                            *
  13. '  To compile this program and link it with Fastgraph version 4.0:           *
  14. '                                                                            *
  15. '    BC /O FADE;                        (QuickBASIC 4.5)                     *
  16. '    LINK FADE,,NUL,FGQB;                                                    *
  17. '                                                                            *
  18. '    BC /Fs /O FADE;                    (BASIC PDS 7.x)                      *
  19. '    LINK FADE,,NUL,FGQBX;                                                   *
  20. '                                                                            *
  21. '    BC /O FADE;                        (Visual Basic for DOS)               *
  22. '    LINK FADE,,NUL,FGVBDOS;                                                 *
  23. '                                                                            *
  24. '  This program also can be linked with Fastgraph/Light version 4.0 if you   *
  25. '  replace the FGxxx library references with FGLxxx.                         *
  26. '                                                                            *
  27. '  Fastgraph (tm) and Fastgraph/Light (tm) are graphics libraries published  *
  28. '  by Ted Gruber Software.  For more info, please call, write, or FAX.       *
  29. '                                                                            *
  30. '  Ted Gruber Software                           orders/info (702) 735-1980  *
  31. '  PO Box 13408                                          FAX (702) 735-4603  *
  32. '  Las Vegas, NV  89112                                  BBS (702) 796-7134  *
  33. '                                                                            *
  34. '*****************************************************************************
  35.  
  36. REM $INCLUDE: 'fastgraf.bi'
  37.  
  38. DEFINT A-Z
  39.  
  40. REM function declarations
  41.  
  42. DECLARE SUB FadeIn (PCXfile$, Delay)
  43. DECLARE SUB FadeOut (Delay)
  44. DECLARE SUB Pack (DacString$, Dacs())
  45. DECLARE SUB Unpack (DacString$, Dacs())
  46.  
  47. REM these values can be changed for different video modes
  48.  
  49. CONST NDACS = 256
  50. CONST NCOLORS = 64
  51. CONST VideoMode = 19
  52. CONST ArraySize = NDACS * 3
  53.  
  54. REM these global arrays hold two complete sets of DAC values
  55.  
  56. DIM SHARED Dacs1(ArraySize) AS INTEGER
  57. DIM SHARED Dacs2(ArraySize) AS INTEGER
  58. DIM SHARED DacString AS STRING*ArraySize
  59.  
  60. REM start of main program
  61.  
  62. REM make sure the requested graphics mode is available
  63.  
  64. IF (FGtestmode(VideoMode,1) = 0) THEN
  65.    PRINT "This program requires a "; NDACS; "-color graphics mode."
  66.    STOP
  67. END IF
  68.  
  69. REM calculate the base delay between DAC updates
  70.  
  71. Delay = FGmeasure / 128
  72.  
  73. REM initialize Fastgraph for the requested video mode
  74.  
  75. OldMode = FGgetmode
  76. FGsetmode VideoMode
  77.  
  78. REM for each PCX file, fade it in and then back out
  79.  
  80. FadeIn "TOMMY.PCX"+CHR$(0), Delay
  81. FGwaitfor 36
  82. FadeOut Delay
  83. FGwaitfor 18
  84.  
  85. FadeIn "BALLOONS.PCX"+CHR$(0), Delay
  86. FGwaitfor 36
  87. FadeOut Delay*2
  88. FGwaitfor 18
  89.  
  90. FadeIn "MOUSE.PCX"+CHR$(0), Delay
  91. FGwaitfor 36
  92. FadeOut Delay*4
  93.  
  94. REM restore the original video mode and screen attributes
  95.  
  96. FGsetmode OldMode
  97. FGreset
  98.  
  99. END
  100.  
  101. '*****************************************************************************
  102. '                                                                            *
  103. '  FadeIn                                                                    *
  104. '                                                                            *
  105. '  Display an image by gradually increasing each DAC's RGB components to     *
  106. '  their original values.                                                    *
  107. '                                                                            *
  108. '*****************************************************************************
  109.  
  110. SUB FadeIn (PCXfile$, Delay)
  111.  
  112. REM get the target DAC values from the PCX file
  113.  
  114. Status = FGpcxpal(PCXfile$,DacString)
  115. Unpack DacString, Dacs1()
  116.  
  117. REM zero all of the DACs
  118.  
  119. DacString = STRING$(ArraySize,0)
  120. FGsetdacs 0, NDACS, DacString
  121. Unpack DacString, Dacs2()
  122.  
  123. REM display the blacked-out PCX image
  124.  
  125. Status = FGshowpcx(PCXfile$,1)
  126.  
  127. REM cycle through the DACs, gradually increasing them to their old values
  128.  
  129. FOR J = 0 TO NCOLORS-1
  130.  
  131.    REM increment each RGB component if it is below its old value
  132.  
  133.    Target = NCOLORS - J
  134.  
  135.    FOR I = 0 TO ArraySize-1
  136.       IF (Dacs1(I) > Target) AND (Dacs2(I) < Dacs1(I)) THEN Dacs2(I) = Dacs2(I) + 1
  137.    NEXT
  138.  
  139.    REM update the DACs each time through the loop
  140.  
  141.    FGstall Delay
  142.    Pack DacString, Dacs2()
  143.    FGsetdacs 0, NDACS, DacString
  144.  
  145. NEXT
  146.  
  147. END SUB
  148.  
  149. '*****************************************************************************
  150. '                                                                            *
  151. '  FadeOut                                                                   *
  152. '                                                                            *
  153. '  Erase an image by gradually fading each DAC's RGB components to black.    *
  154. '                                                                            *
  155. '*****************************************************************************
  156.  
  157. SUB FadeOut (Delay)
  158.  
  159. REM load the dacs1 and dacs2 arrays with the current DAC values
  160.  
  161. FGgetdacs 0, NDACS, DacString
  162. Unpack DacString, Dacs1()
  163. Unpack DacString, Dacs2()
  164.  
  165. REM cycle through the DACs, gradually reducing them to 0 (black)
  166.  
  167. FOR J = 0 TO NCOLORS-1
  168.  
  169.    REM decrement each RGB component if it is above 0
  170.  
  171.    FOR I = 0 TO ArraySize-1
  172.       IF (Dacs2(I) > 0) THEN Dacs2(I) = Dacs2(I) - 1
  173.    NEXT
  174.  
  175.    REM update the DACs each time through the loop
  176.  
  177.    FGstall Delay
  178.    Pack DacString, Dacs2()
  179.    FGsetdacs 0, NDACS, DacString
  180.  
  181. NEXT
  182.  
  183. END SUB
  184.  
  185. '*****************************************************************************
  186. '                                                                            *
  187. '  Pack                                                                      *
  188. '                                                                            *
  189. '  Pack the values from an integer array into a string variable.             *
  190. '                                                                            *
  191. '*****************************************************************************
  192.  
  193. SUB Pack (DacString$, Dacs())
  194.  
  195. FOR I = 0 TO ArraySize-1
  196.    MID$(DacString$,I+1,1) = CHR$(Dacs(I))
  197. NEXT
  198.  
  199. END SUB
  200.  
  201. '*****************************************************************************
  202. '                                                                            *
  203. '  Unpack                                                                    *
  204. '                                                                            *
  205. '  Unpack the values from a string variable into an integer array.           *
  206. '                                                                            *
  207. '*****************************************************************************
  208.  
  209. SUB Unpack (DacString$, Dacs())
  210.  
  211. FOR I = 0 TO ArraySize-1
  212.    Dacs(I) = ASC(MID$(DacString$,I+1,1))
  213. NEXT
  214.  
  215. END SUB
  216.